package com.betterjr.modules.bank.dubbo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.dubbo.config.annotation.Service;
import com.betterjr.common.web.AjaxObject;
import com.betterjr.modules.bank.dubbo.interfaces.IBankCityNoService;
import com.betterjr.modules.bank.entity.BankCityNo;
import com.betterjr.modules.bank.service.BankCityNoService;

@Service(interfaceClass = IBankCityNoService.class)
public class BankCityNoDubboService implements IBankCityNoService {
    @Inject
    BankCityNoService bankCityNoService;

    /** 
     * <p>Description: </p> 
     * @see com.betterjr.modules.bank.dubbo.interfaces.IBankCityNoService#queryCityForSelect(java.lang.String) 
     * @author licz
     * @date 2018年7月13日 上午9:18:30 
     */
    @Override
    public String queryCityForSelect(final String anProvinceName) {
        final List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Object> recod = null;

        if (StringUtils.isBlank(anProvinceName)) {
            final List<String> provinces = bankCityNoService.queryProvinceNames();
            // 按照前台需要的格式返回数据 --------- //TODO 按需前台自己处理封装数据格式

            for (final String province : provinces) {
                recod = new HashMap<>();
                recod.put("value", province);
                recod.put("label", province);
                recod.put("children", new String[] {});
                recod.put("loading", false);
                resultList.add(recod);
            }

        } else {
            final List<BankCityNo> dataList = bankCityNoService.selectByProperty("provinceName", anProvinceName);
            // 按照前台需要的格式返回数据 --------- //TODO 按需前台自己处理封装数据格式
            for (final BankCityNo bankCity : dataList) {
                recod = new HashMap<>();
                recod.put("value", bankCity.getCityCode());
                recod.put("label", bankCity.getCityName());
                resultList.add(recod);
            }
        }

        return AjaxObject.newOk("成功", resultList).toJson();

    }

}
